package com.hjxr.sysadmin.zsj.controller;

import com.hjxr.framework.aspectj.lang.annotation.Log;
import com.hjxr.framework.aspectj.lang.enums.BusinessType;
import com.hjxr.framework.web.domain.AjaxResult;
import com.hjxr.sysadmin.uitl.poi.ExcelUtil;
import com.hjxr.sysadmin.web.controller.BaseController;
import com.hjxr.sysadmin.web.page.TableDataInfo;
import com.hjxr.sysadmin.zsj.domain.UserProject;
import com.hjxr.sysadmin.zsj.service.IUserProjectService;
import io.swagger.annotations.Api;
import io.swagger.annotations.ApiOperation;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.*;

import java.util.List;
import java.util.Map;


/**
 * 用户项目Controller
 *
 * @author hjxr
 * @date 2021-04-16
 */
@Api("用户项目信息")
@RestController
@RequestMapping("/userProject")
public class UserProjectController extends BaseController
{
    @Autowired
    private IUserProjectService userProjectService;

    /**
     * 查询用户项目列表
     */
    @ApiOperation("查询用户项目信息列表")
    @GetMapping(value = "list")
    public TableDataInfo list(UserProject userProject){
        startPage();
        System.out.println(userProject);
        List<Map<String,Object>> list = userProjectService.selectUserProject(userProject);
        return getDataTable(list);
    }

    /**
     * 导出用户项目列表
     */
    @Log(title = "用户项目", businessType = BusinessType.EXPORT)
    @GetMapping("/export")
    public AjaxResult export(UserProject userProject)
    {
        List<UserProject> list = userProjectService.selectUserProjectList(userProject);
        ExcelUtil<UserProject> util = new ExcelUtil<UserProject>(UserProject.class);
        return util.exportExcel(list, "project");
    }

    /**
     * 获取用户项目详细信息
     */
    @GetMapping(value = "/{userProjectId}")
    public AjaxResult getInfo(@PathVariable("userProjectId") Long userProjectId)
    {
        return AjaxResult.success(userProjectService.selectUserProjectById(userProjectId));
    }

    /**
     * 新增用户项目
     */
    @Log(title = "用户项目", businessType = BusinessType.INSERT)
    @PostMapping
    public AjaxResult add(@RequestBody UserProject userProject)
    {
        return toAjax(userProjectService.insertUserProject(userProject));
    }

    /**
     * 修改用户项目
     */
    @Log(title = "用户项目", businessType = BusinessType.UPDATE)
    @PutMapping
    public AjaxResult edit(@RequestBody UserProject userProject)
    {
        return toAjax(userProjectService.updateUserProject(userProject));
    }

    /**
     * 删除用户项目
     */
    @Log(title = "用户项目", businessType = BusinessType.DELETE)
	@DeleteMapping("/{userProjectIds}")
    public AjaxResult remove(@PathVariable Long[] userProjectIds)
    {
        return toAjax(userProjectService.deleteUserProjectByIds(userProjectIds));
    }
}
